<template>
  <div>
    <Tabs :value="currentTab" @on-click="handleTabChange">
      <TabPane label="全部" name="name1"></TabPane>
      <TabPane label="我参加的" name="name2"></TabPane>
    </Tabs>
    <div class="list">
      <div
        class="list-item"
        v-for="(item, index) in showList"
        :key="item.id"
        @click="toDetail(item.id)"
      >
        <div class="list-item1">
          <div class="title">
            {{ item.title }}
            <a
              v-show="item.join === 1"
              @click.stop="toWorkDetail(index)"
              class="toWorkDetail"
              >作品详情</a
            >
          </div>
          <div class="timeSlot">
            <!-- <img :src="item.thumb" alt="" /> -->
            <Avatar
            shape="square"
            :src="item.thumb"
            @on-error="(val)=>val.target.src = require('@/assets/communityimg/avatar.png')"
            icon="ios-person"
            size="28"
          />
            <div class="time">
              报名时间：{{ item.ready_stime }}-{{ item.ready_time }}
            </div>
          </div>
        </div>
        <div
          class="list-item2"
          :class="{ ing: getStatus(item) === '活动进行中' ||getStatus(item) === '活动报名中'  }"
        >
          {{ getStatus(item) }}
        </div>
      </div>
    </div>
    <Modal v-model="modal1" footer-hide width="1000">
      <div class="modalBox">
        <div class="modal-title">
          <img class="avatar" :src="md.thumb" alt="" />
          <div class="info">
            <div class="info-name">{{ md.name }}</div>
            <div class="info-time">{{ md.createTime }}</div>
          </div>
        </div>
        <div class="modal-content">
          <div class="content-title">{{ md.title }}</div>
          <div class="content-text">
            {{ md.content }}
          </div>
          <video class="content-video" :src="md.thumb"></video>
        </div>
      </div>
    </Modal>
  </div>
</template>

<script>
import { pactivity, usactivity } from "@/api/community";
import { time } from "@/config/time";
export default {
  props: {},
  components: {},

  data() {
    return {
      currentTab: "name1",
      md: {},
      info: [],
      myInfo: [],
      modal1: false,
    };
  },
  created() {},
  onload(option) {
    console.log(option);
  },
  mounted() {
    this.getpactivity();
  },
  watch: {},
  computed: {
    showList() {
      if (this.currentTab === "name2") {
        return this.myInfo;
      }
      return this.info;
    },
  },
  methods: {
    handleTabChange(val) {
      this.currentTab = val;
      if (val === "name2") {
        this.getMyInfo();
      }
      if (val === "name1") {
        this.getpactivity();
      }
    },
    getMyInfo() {
      usactivity({
        mid: JSON.parse(localStorage.userInfo).id,
        page: 1,
        pagesize: 1000,
      }).then((res) => {
        if (res.code === 1) this.myInfo = res.data;
        this.myInfo.map((item) => {
          item.ready_stime = time.getallTime(item.ready_stime);
          item.ready_time = time.getallTime(item.ready_time);
          item.act_stime = time.getallTime(item.act_stime);
          item.act_time = time.getallTime(item.act_time);
        });
        // console.log(res,'我参加的活动');
      });
    },
    // 获取全部活动的基本数据
    getpactivity() {
      let pac = {
        mid: JSON.parse(localStorage.userInfo).id,
        page: 1,
        pagesize: 10000,
      };
      pactivity(pac).then((res) => {
        this.info = res.data;
        console.log(123, this.info);
        this.info.map((item) => {
          item.ready_stime = time.getallTime(item.ready_stime);
          item.ready_time = time.getallTime(item.ready_time);
          item.act_stime = time.getallTime(item.act_stime);
          item.act_time = time.getallTime(item.act_time);
        });
      });
    },
    getStatus(item) {
      const currentTime = new Date().getTime();
      const activeStartTime = new Date(item.act_stime).getTime();
      const activeEndTime = new Date(item.act_time).getTime();
      const ready_stime = new Date(item.ready_stime).getTime();
      const ready_time = new Date(item.ready_time).getTime();
      if (currentTime > ready_stime && currentTime < ready_time) {
        return "活动报名中";
      } else if (currentTime < activeStartTime) {
        return "活动未开始";
      } else if (currentTime > activeStartTime && currentTime < activeEndTime) {
        return "活动进行中";
      } else if (currentTime > activeStartTime) {
        return "活动已结束";
      }
    },
    toWorkDetail(id) {
      this.modal1 = true;
      this.md = this.info[id];
      console.log(this.md, "123");
    },
    toDetail(id) {
      this.$router.push({
        path: "/active-detail",
        query: {
          id,
        },
      });
    },
  },
};
</script>

<style scoped lang="scss">
.modalBox {
  padding: 40px;
  .modal-title {
    display: flex;
    align-items: center;
    .avatar {
      width: 50px;
      height: 50px;
      display: inline-block;
      border-radius: 50%;
    }
    .info {
      display: flex;
      flex-direction: column;
      margin-left: 12px;
      .info-name {
        color: #333333;
        font-size: 14px;
      }
      .info-time {
        color: #acacac;
        font-size: 12px;
      }
    }
  }
  .modal-content {
    margin-left: 50px;
    .content-title {
      color: #333333;
      font-size: 14px;
      font-weight: 500;
    }
    .content-text {
      font-weight: 400;
      margin-bottom: 20px;
      margin-top: 17px;
    }
    .content-video {
      width: 100%;
    }
  }
}

.list {
  .list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #ececec;
    &:last-child {
      border: none;
    }
    .list-item2 {
      width: 100px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-top-left-radius: 8px;
      border-bottom-left-radius: 8px;
      background-color: #e7e7e7;
      color: #a3a3a3;
    }
    .list-item2.ing {
      background-color: #dcf8ee;
      color: #35b572;
    }
    .list-item1 {
      padding: 13px;
      .title {
        color: #333333;
        font-size: 16px;
        font-weight: 500;
        .toWorkDetail {
          color: #2f7de7;
          font-size: 14px;
          text-decoration: underline;
        }
      }
      .timeSlot {
        display: flex;
        align-items: center;
        margin-top: 4px;
        img {
          display: inline-block;
          width: 18px;
          height: 18px;
        }
        .time {
          color: #878583;
          margin-left: 9px;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
